using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Park.Net.IService;
using Park.Net.Model;
using Park.Net.Utils;

namespace Park.Net.ParkWebAPI.Controllers
{
    //查
    [ApiController]
    [Route("api/[controller]")]
    public class RentController : ControllerBase
    {
         private readonly IBaseServices<Rent> _RentService;

        public RentController(IBaseServices<Rent> RentService)
        {
            _RentService = RentService;
        }

        [HttpGet("Rent")]
        public async Task<ActionResult<ApiReturns>> GetRent()
        {
            var res = await _RentService.FindAllAsync();
            if (res != null && res.Count > 0)
            {
                return ApiReturnsHelper.Succeed(res);
            }
            return ApiReturnsHelper.Failed("查不到~");
        }
    }
     // 添加
public class RentAddController : ControllerBase
{
    private readonly IBaseServices<Rent> _context;

    public RentAddController(IBaseServices<Rent> context)
    {
        _context = context;
    }

    // POST: api/Bike/AddBike
    [HttpPost]
    [Route("RentAdd")]
    public async Task<ActionResult> AddBike(Rent bike )
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        // Perform additional validation as needed
        // if (string.IsNullOrEmpty(bike.Name) || string.IsNullOrEmpty(bike.Password)|| string.IsNullOrEmpty(bike.Phone))
        // {
        //     return BadRequest("Bike number and type are required fields.");
        // }

        // Add bike data to the database
       await _context.CreateAsync(bike);
      
        return Ok($"Bike with ID {bike.ID} was added successfully.");
    }
}
}
